Q: Boolean results from pswrap functions are wrong. I use:\
\
\f2 defineps foo ( | boolean *b)\
...\
endps\
\f1 \
And later, in my ObjC code,\
\
\f2 BOOL B;\
foo (&B);\
\f1 \
B contains 0 no matter what foo() returns. What's wrong?\
\
A: The client library is fine; the real problem is type mismatch, which COULD have been detected by using the type-checking ability of the compiler. In the pswrap-generated code, the boolean b is really an int. The BOOL type of Objective-C, however, is an unsigned char. Thus, if you use the boolean declaration at the pswrap end, you should use int in the C code. The pswrap code would still look like this:\
\
\f2 defineps foo (| boolean *b)\
...\
endps\
\f1 \
However, the ObjC code will look like this:\
\
\f2 int B;\
foo (&B);\
\f1 \
When passing booleans back and forth, remember that on the PostScript side a value of 0 will be translated into a PostScript boolean object whose value is
\i false
\i0 . Any other value will be translated to a PostScript boolean object whose value is
\i true
\i0 .\
\
The above problem can be caught by using the "-a" flag to pswrap to generate ANSI prototypes and import the generated file. By default, pswrap does not generate full prototypes and the above problem is missed at compile time. \